<?php
/*
 * site/load-index.phtml
 * Chargement de la liste des Sites en AJAX
 */
?>
<?php
$siteList = $this->siteList;
?>
<div class='content-body'>
    <div class='list-container'>
	<table class="table table-striped list-table">
	    <thead>
		<tr>
		    <td width='30%'>Libellé</td>
		    <td width='45%'>Adresse</td>
		    <td width='12%'>&nbsp;</td>
		</tr>
	    </thead>
	    <tbody>
	<?php foreach ($siteList as $site): ?>
		<tr>
		    <td style="text-align: center;">
			
                        <?php echo $site->libelle; ?>
    		    </td>
    		    <td>
			<?php echo $site->adresse; ?>    			
    		    </td>
		    <td style='text-align: center;'>
        
    			&nbsp;&nbsp;&nbsp;                        
                        <a href='<?php echo $this->url('RHX/default', array('controller'	 => 'site', 'action'	 => 'edit', 'id' => $site->id )) ?>' id='edit-<?php echo $site->id; ?>' class="edit-site" data-site="<?php echo $site->id; ?>" ><img src='<?php echo $this->basePath() . '/img/rhx/edit-16x15.png' ?>' alt='Editer' title='Editer'></a>
			&nbsp;&nbsp;&nbsp; 
                        <a href='#' id='delete-<?php echo $site->id; ?>' class="delete-site" data-site="<?php echo $site->id; ?>" data-name="<?php echo $site->libelle; ?>">
    			    <img src='<?php echo $this->basePath() . '/img/rhx/delete-16x16.png' ?>' alt='Effacer' title='Effacer'>
			</a>			
    		    </td>
    		</tr>
<?php endforeach; ?>
	    </tbody>
	</table>
    </div>
</div>

<script type="text/javascript">
    // Démarrage
    $(function(){
	
	$('.delete-site').click(function(e){
	    e.preventDefault();
	    name = $(this).attr('data-name');
	    conf = confirm("Voulez-vous effacer le site " + name + " ?");
	    if(!conf){
		return false;
	    }
	    site = $(this).attr('data-site');
	    ajax = $.ajax({
		type: 'post',
		url : '<?php echo $this->url('RHX/default', array('controller'	 => 'site', 'action'	 => 'delete')) ?>',
		data: '&site='+ site
	    });
	    ajax.done(function(result){
		if(result.done){
		    updateList();
		}else{
		    alert(result.error);
		}
	    });
	});
    });

    // Rendre éditable l
</script>